import { getRoleList } from "@/service/api/role"
export default {
    namespaced: true,
    state: () => ({
        // 角色列表
        roleList: [],
        errorList: []
    }),
    mutations: {
        setRoleList(state, roleList) {
            state.roleList = roleList
        },
        setErrorList(state, errorList) {
            //以空格为间隔插入到数组中
            errorList = errorList.replace(/\n\n/g, "。");
            errorList = errorList.replace(/\n/g, "、");

            let entries = errorList.split('。');
            entries = entries.map(entry => entry.trimEnd());
            entries.pop();

            state.errorList = entries
        }
    },
    actions: {
        async getRoleList() {
            const data = await getRoleList();
            const roleList = data.rows.map((row) => ({
                roleId: row.roleId,
                roleName: row.roleName
            }))
            this.commit('userManagement/setRoleList', roleList);
        }
    }
}